﻿using LitJson;
using System.Collections.Generic;
using System.IO;
using HeerCards.Helper;

namespace Code
{
    public class AppReloader
    {
        /// <summary>
        /// 加载到App.Pools卡池
        /// </summary>
        public static void LoadPools()
        {
            //读取卡池列表
            AppMain.Pools = new List<HeerCards.HCPool>();
            if (!Directory.Exists(AppMain.Common.AppDirectory + "pools"))
            {
                Directory.CreateDirectory(AppMain.Common.AppDirectory + "pools");
            }
            foreach (var item in Directory.GetFiles(AppMain.Common.AppDirectory + "pools", "*.json"))
            {
                AppMain.Pools.Add(JsonMapper.ToObject<HeerCards.HCPool>(new JsonReader(File.ReadAllText(item))));
            }
        }

        public static void LoadGobal()
        {
            #region 读取全局设置

            var path = AppMain.Common.AppDirectory + "GobalSettings.json";
            AppMain.GobalSetting = HCConfigLoader.loadGobalSettingFromFile(path);
            #endregion
        }

        public static void LoadCosts()
        {
            #region 读取货币单元

            var path = AppMain.Common.AppDirectory + "CostUnits.json";
            AppMain.CostUnits = HCConfigLoader.loadCostUnitsFromFile(path);
            if (AppMain.CostUnits.Count == 0)
            {
                //不存在货币单元
            }

            #endregion 读取货币单元
        }

        public static void LoadVIP()
        {
            //检测VIP
            if (AppMain.VipInfo == null)
            {
                AppMain.VipInfo = new HeerCards.Info.VIPInfo() { isVIP=false,VIPName=""};
            }
            ProCodeSaver ps = new ProCodeSaver();
            ps.Dir = AppMain.Common.AppDirectory;
            var code = ps.loadCode(AppMain.Common.AppDirectory);
            if (code != "")
            {
                var r = VIPHelper.checkVIP(AppMain.Common.GetLoginQQ().Id.ToString(), code);
                AppMain.VipInfo = r;
            }
            else
            {
                AppMain.VipInfo.isVIP = false;
            }
        }
        public static void LoadImageDLC()
        {
            AppMain.ImageDLCManager = new github.heerheer.card2.Code.ImageHelper.ImageDLCManager();
        }
    }
}